package demo_03;

import java.sql.*;

public class Demo_01 {
    public static void main(String[] args) {
        String driver = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/jdbc";
        String user = "root";
        String pwd = "admin";
        Connection conn = null;
        PreparedStatement stmt = null;
        ResultSet rst = null;

        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
            conn = DriverManager.getConnection(url, user, pwd);
            String sql = "update tbl_book_info set b_name=?,b_price = ?/n"
                    +"where b_id =?";
            stmt = conn.prepareStatement(sql);
            stmt.setString(1,"特朗普");
            stmt.setString(2,"250");
            stmt.setString(3,"3");
            int r =stmt.executeUpdate();

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if (rst != null) {
                try {
                    rst.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                } finally {
                    rst = null;
                }
            }
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                } finally {
                    stmt = null;
                }
            }
            if (conn != null) {
                try {
                    rst.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                } finally {
                    rst = null;
                }
            }
        }

    }
}
